package com.eduhzy.ttw.teacher.di.module;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.ClassTeacherData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.mvp.contract.ClassTransferContract;
import com.eduhzy.ttw.teacher.mvp.model.ClassTransferModel;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-7-17 10:51:03
 */
@Module
public abstract class ClassTransferModule {

    @Binds
    abstract ClassTransferContract.Model bindClassTransferModel(ClassTransferModel model);

    @ActivityScope
    @Provides
    static List<ClassTeacherData> provideList() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    static BaseQuickAdapter<ClassTeacherData, AutoBaseViewHolder> provideActivityAdapter(List<ClassTeacherData> list) {
        return new BaseQuickAdapter<ClassTeacherData, AutoBaseViewHolder>(R.layout.rv_item_class_teacher, list) {
            @Override
            protected void convert(AutoBaseViewHolder helper, ClassTeacherData item) {
                Glide.with(helper.itemView.getContext())
                        .load(item.getTempAvatar())
                        .apply(RequestOptions.placeholderOf(R.drawable.img_touxiang).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL))
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                helper.setText(R.id.tv_teacher_name, item.getRealName());
                helper.setText(R.id.tv_subject, item.getSubjectName());
                helper.setGone(R.id.tv_creator, item.isBzr());
            }
        }

                ;
    }

    @ActivityScope
    @Provides
    static RecyclerView.LayoutManager provideLayoutManger(ClassTransferContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }
}